package com.pactera.madp.cp.interceptor;

import com.pactera.madp.common.security.annotation.Inner;
import com.pactera.madp.cp.service.impl.AccountService;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 企业后管权限校验
 */
@Component
public class AuthorityInterceptor implements HandlerInterceptor{

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        HandlerMethod hm = (HandlerMethod)handler;
        if(hm.getMethod().getAnnotation(Inner.class) != null
                || hm.getBeanType().getAnnotation(Inner.class) != null) {
            return true;
        }
        return AccountService.isAuthority();
    }

}
